package apache.commons;


import org.apache.commons.lang.builder.EqualsBuilder;

public class EqualsBuilderDemo {
	class MyBean {
		int intValue;
		String text;
		double doubleValue;
		public MyBean(int intValue, String text, double doubleValue) {
			this.intValue = intValue;
			this.text = text;
			this.doubleValue = doubleValue;
		}
		
		
	}
	
	class MyBeanChild extends MyBean {
		long longValue;
		public MyBeanChild(int intValue, String text, double doubleValue) {
			super(intValue, text, doubleValue);
		}
		
		public MyBeanChild(int intValue, String text, double doubleValue, long longValue) {
			super(intValue, text, doubleValue);
			this.longValue = longValue;
		}
		
	}
	
	public static void main(String[] args) {
		testSimpleEquals();
		testExtendsEquals();
		testExtendsEqualsExcludeFields();
	}
	
	
	private static void testSimpleEquals() {
		MyBean b1 = new EqualsBuilderDemo().new MyBean(1, "abc", 2d);
		MyBean b2 = new EqualsBuilderDemo().new MyBean(1, "abc", 2d);
		System.out.println(EqualsBuilder.reflectionEquals(b1, b2));
	}
	
	private static void testExtendsEquals() {
		MyBeanChild c1 = new EqualsBuilderDemo().new MyBeanChild(1, "abc", 2d, 3l);
		MyBean b1 = new EqualsBuilderDemo().new MyBean(1, "abc", 2d);
		print((EqualsBuilder.reflectionEquals(b1, c1)));

	}
	
	private static void testExtendsEqualsExcludeFields() {
		MyBeanChild c1 = new EqualsBuilderDemo().new MyBeanChild(1, "abc", 2d, 3l);
		MyBean b1 = new EqualsBuilderDemo().new MyBean(1, "abc", 2d);
		print((EqualsBuilder.reflectionEquals(b1, c1, new String[]{"longValue"})));

	}
	
	private static void print(Object o) {
		System.out.println(o);

	}
}
